﻿using QD.DbManager.DbContent;
using QD_Clients.Code.DbContent;
using QD_Clients.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using QD.Tools;

namespace QD_Clients
{
    public partial class PlatformSetting : Form
    {
        public PlatformSetting()
        {
            InitializeComponent();

            this.StartPosition = FormStartPosition.CenterScreen;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
        }

        private void PlatformSetting_Load(object sender, EventArgs e)
        {
            QDDevPlat_V4 db = new QDDevPlat_V4();
            QDConfig mod = db.QDConfig.First();
            if (mod != null)
            {
                this.IsIEnglish.Checked = mod.IsIEnglish;
                this.IsIJapanese.Checked = mod.IsIJapanese;
                this.IsMaintaining.Checked = mod.IsMaintaining;
            }

            this.KeyPreview = true;
            this.KeyDown += Sys_SyncSettingMag_KeyDown;
        }
        private void tsbtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                QDDevPlat_V4 db = new QDDevPlat_V4();
                QDConfig mod = db.QDConfig.First();
                if (mod == null)
                {
                    mod = new QDConfig();
                    mod.IsEnableCopyright = true;
                    db.QDConfig.Add(mod);
                }
                mod.IsIEnglish = this.IsIEnglish.Checked;
                mod.IsIJapanese = this.IsIJapanese.Checked;
                mod.IsMaintaining = this.IsMaintaining.Checked;

                db.SaveChanges();
                PromptHelper.Prompt("设置成功！");
            }
            catch (Exception ex)
            {
                PromptHelper.Prompt(ex);
            }
        }

        private void Sys_SyncSettingMag_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Modifiers == Keys.Control && e.KeyCode == Keys.S)
            {
                tsbtnSave_Click(sender, e);
            }
        }
    }
}
